package com.lili.operate.service.serviceImpl;

import com.lili.model.operate.ArticleCategory;
import com.lili.operate.mapper.ArticleCategoryMapper;
import com.lili.operate.service.ArticleCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ArticleCategoryServiceImpl implements ArticleCategoryService {

    @Autowired
    ArticleCategoryMapper articleCategoryMapper;

    /**
     * 新增文章分类
     * @param articleCategory
     * @return
     */
    @Override
    public int saveArticleCategory(ArticleCategory articleCategory) {
        return articleCategoryMapper.insert(articleCategory);
    }

    /**
     * 查询所有的文章分类
     * @return
     */
    @Override
    public List<Map> queryArticleCategory() {
        return articleCategoryMapper.queryArticleCategory();
    }

    /**
     * 更新文章分类
     * @param articleCategory
     * @return
     */
    @Override
    public int updateArticleCategory(ArticleCategory articleCategory) {
        return articleCategoryMapper.updateById(articleCategory);
    }

    /**
     * 根据id删除文章分类
     * @param id
     * @return
     */
    @Override
    public int deleteArticleCategory(long id) {
        //先查询是否有子类
        List<ArticleCategory> list = articleCategoryMapper.querySon(id);
        if(list.size()==0){
            return 0;
        }
        return articleCategoryMapper.deleteArticleCategory(id);
    }
}
